<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');

class Page2_css extends Admin_Controller
{
	/**
	* called in module
	*/
    var $access_supperadmin = 1;
	function dropdown()
	{
		global $CI;
		
		// model
		$CI->load->module_model('page2_css.page2_css_dropdown_model');
		
		// add to view
		$this->add('name', $CI->page2_css_dropdown_model->name);
		$this->add('onchange', $CI->page2_css_dropdown_model->onchange);
		$this->add('value', $CI->page2_css_dropdown_model->value);
		$this->add('items', $CI->page2_css_dropdown_model->items);
		
		// view
		$this->view('page2_css_dropdown_view');
	}
		
	function lists()
	{
		global $CI;
		
		// model
		$CI->load->module_model('page2_css.page2_css_list_model');
		
		// filter
		if (isset($_POST['filter']))
			$CI->page2_css_list_model->cache->add($CI->page2_css_list_model->filter_cache_prefix, $_POST['filter']);

		// sql
		$CI->db->where(PAGE_CSS.'.'.PAGE_CSS_FRANCHISE_ID, $CI->page2_css_list_model->admin_id());
		$q = $CI->db->get(PAGE_CSS);
		
		// pagenavigation
		$CI->load->library('pagination');
        $config['base_url'] = site_url($CI->page2_css_list_model->url_prefix.'/%s');
        $config['total_rows'] = $q->num_rows();
        $config['per_page'] = $CI->config->item('rows_per_page');
		$config['cur_page'] = $CI->page2_css_list_model->start;
		$config['num_links'] = $CI->config->item('num_links');		
        $CI->pagination->initialize($config);
        $this->add('paging', $CI->pagination->create_links());
		
		// sql
		$CI->db->from(PAGE_CSS);
		$CI->db->select('*');
		//$CI->db->where(PAGE_CSS.'.'.PAGE_CSS_FRANCHISE_ID, $CI->page2_css_list_model->admin_id());
		foreach ($CI->page2_css_list_model->columns as $k=>$v)
		{
			if ($CI->page2_css_list_model->cache->load($k))
				$CI->db->order_by($v, $CI->page2_css_list_model->cache->load($k));
		}
		$CI->db->limit($CI->config->item('rows_per_page'), $CI->page2_css_list_model->start);
		$q = $CI->db->get();
		
		// gridview
		$this->add('items', $q->result());
		$this->add('start', $CI->page2_css_list_model->start);
		foreach ($CI->page2_css_list_model->columns as $k=>$v)
		{
			if ($CI->page2_css_list_model->cache->load($k))
				$this->add('sort_'.$k,  'class="sort_column_'.$CI->page2_css_list_model->cache->load($k).'"');
			else
				$this->add('sort_'.$k,  '');
		}

		// message
		$this->add('msg', $CI->page2_css_list_model->cache->load($CI->page2_css_list_model->msg_cache_prefix));
		$CI->page2_css_list_model->cache->add($CI->page2_css_list_model->msg_cache_prefix, '');
		
		// toolbar
		$this->module_toolbar('page2_css.toolbar', array('parent_id'=>0, 'start'=>$CI->page2_css_list_model->start));
		$this->module_navigation('Page Theme Management');
		
		// view
		$this->view('page2_css_list_view');
	}
	
	function detail()
	{
		global $CI;
		
		// model
		$CI->load->module_model('page2_css.page2_css_detail_model');
		
		// sql	
		$q = $CI->db->get_where(PAGE_CSS, array(PAGE_CSS_PAGE_CSS_ID=>$CI->page2_css_detail_model->item));
		$entity = $q->row();
		
		// error
		$post = $CI->page2_css_detail_model->cache->load('post');
		$CI->page2_css_detail_model->cache->add('post', '');

		// add to view
		$this->add('css_file', $post?$post['css_file']:($entity?$entity->{PAGE_CSS_CSS_FILE}:''));
		$this->add('note', $post?$post['note']:($entity?$entity->{PAGE_CSS_NOTE}:''));
		
		// add to view
		$this->add('start', $CI->page2_css_detail_model->start);
		$this->add('item_id', $CI->page2_css_detail_model->item);

		// message
		$this->add('msg', $CI->page2_css_detail_model->cache->load($CI->page2_css_detail_model->msg_cache_prefix));
		$CI->page2_css_detail_model->cache->add($CI->page2_css_detail_model->msg_cache_prefix, '');
		
		// toolbar
		$this->module_toolbar();
		if ($CI->page2_css_detail_model->item)
			$this->module_navigation('Page Theme : Edit');
		else
			$this->module_navigation('Page Theme : New');
			
		// view
		$this->view('page2_css_detail_view');
	}
}

?>